<?php

class ImgList extends MY_Controller{

    public function __construct(){
        parent::__construct();
    }

    /**
     * 获取图库列表
     * name: index
     * @Author:taiyang
     *
     *
     */
    public function index(){
        //$type='',$tag_id='',$is_related=''
        $type=$this->input->get_post('type')?$this->input->get_post('type'):'';
        $tag_id=$this->input->get_post('tag_id')?$this->input->get_post('tag_id'):'';
        $is_related=$this->input->get_post('is_related')?$this->input->get_post('is_related'):'';
        $page=$this->input->get_post('page')?$this->input->get_post('page'):1;
        $pagesize=$this->input->get_post('pagesize')?$this->input->get_post('pagesize'):10;
        $list=$this->ImgModel->getImgList($type,$tag_id,$is_related,'',$page,$pagesize);
        $num=$this->ImgModel->getImgListNum($type,$tag_id,$is_related);
        $tag=$this->ImgTagModel->getList(array('parent_id'=>0), 0);
        //分页
        $url = 'index.php?c=imgList&m=index&type='.$type.'&tag_id='.$tag_id.'&is_related='.$is_related;
        $multipage = multipage($num, $page, $pagesize, $url);
        $pageTitle = "图库列表";
        $this->load->view('imglist/index',array(
            "pageTitle" => $pageTitle,
            "type" => $type,
            "tag_id" => $tag_id,
            "tag" => $tag,
            "is_related" => $is_related,
            "list" => $list,
            "multipage" => $multipage,
        ));
    }

    /**
     * 删除图片
     */
    public function del_up_img(){
        $id = $this->input->get_post("id");
        $this->ImgModel->del_data(array("id" => $id));
        $this->ImgToTagModel->del_data(array("img_id" => $id));
        std_out(0,"");
    }

    /**
     * 获取图库列表
     * name: index
     * @Author:taiyang
     *
     *
     */
    public function img_list(){
        //$type='',$tag_id='',$is_related=''
        $id=$this->input->get_post('id')?$this->input->get_post('id'):0;
        $type=$this->input->get_post('type')?$this->input->get_post('type'):'';
        $tag_id=$this->input->get_post('tag_id')?$this->input->get_post('tag_id'):'';
        $is_hege=$this->input->get_post('is_hege')?$this->input->get_post('is_hege'):1;
        $is_related=$this->input->get_post('is_related')?$this->input->get_post('is_related'):1;
        $page=$this->input->get_post('page')?$this->input->get_post('page'):1;
        $pagesize=$this->input->get_post('pagesize')?$this->input->get_post('pagesize'):21;
        $list=$this->ImgModel->getImgList($type,$tag_id,$is_related,$is_hege,$page,$pagesize);
        $num=$this->ImgModel->getImgListNum($type,$tag_id,$is_related,$is_hege);
        $tag=$this->ImgTagModel->getList(array('parent_id'=>0), 0);
        //分页
        $url = 'index.php?c=imgList&m=ajax_img_list&id='.$id.'&tag_id='.$tag_id.'&is_related='.$is_related.'&type='.$type.'&is_hege='.$is_hege;
        $multipage = ajax_multipage($num, $page, $pagesize, $url, "data_img_list", "page_img_list");

//        $multipage = multipage($num, $page, $pagesize, $url);
        $pageTitle = "图库列表";
        $this->load->view('imglist/img_list',array(
            "pageTitle" => $pageTitle,
            "type" => $type,
            "is_hege" => $is_hege,
            "tag_id" => $tag_id,
            "id" => $id,
            "tag" => $tag,
            "is_related" => $is_related,
            "list" => $list,
            "multipage" => $multipage,
        ));
    }


    public function ajax_img_list(){

        $id=$this->input->get_post('id')?$this->input->get_post('id'):0;
        $type=$this->input->get_post('type')?$this->input->get_post('type'):'';
        $tag_id=$this->input->get_post('tag_id')?$this->input->get_post('tag_id'):'';
        $is_hege=$this->input->get_post('is_hege')?$this->input->get_post('is_hege'):1;
        $is_related=$this->input->get_post('is_related')?$this->input->get_post('is_related'):1;
        $page=$this->input->get_post('page')?$this->input->get_post('page'):1;
        $pagesize=$this->input->get_post('pagesize')?$this->input->get_post('pagesize'):21;
        $list=$this->ImgModel->getImgList($type,$tag_id,$is_related,$is_hege,$page,$pagesize);
        $num=$this->ImgModel->getImgListNum($type,$tag_id,$is_related,$is_hege);
        $tag=$this->ImgTagModel->getList(array('parent_id'=>0));
        //分页
        $url = 'index.php?c=imgList&m=ajax_img_list&id='.$id.'&tag_id='.$tag_id.'&is_related='.$is_related.'&type='.$type.'&is_hege='.$is_hege;
        $multipage = ajax_multipage($num, $page, $pagesize, $url, "data_img_list", "page_img_list");

//        $multipage = multipage($num, $page, $pagesize, $url);

        $html='';



        foreach($list as $img){
            $w=$img['w']>$img['h']?110:'';
            $h=$img['h']>$img['w']?110:'';
            $w=$img['w']==$img['h']?110:$w;
            $is_hege=$img['w']<720?'不合格':($img['h']<720?'不合格':($img['size']<20480?'不合格':'合格'));
            $html.='<div class="img_d"  style="text-align: center;"  id="img_del_'.$img['id'].'">
                <button type="button" class="close_del" aria-label="Close" style="" onclick="del_img_id('.$img['id'].')"><span aria-hidden="true">&times;</span></button>
                <a   onclick="check_img(\''.$id.'\',\''.$img["path"].'?x-oss-process=style/scale-cade2\',\''.$img["id"].'\')" style="line-height:120px;" 
                title="宽'.$img['w'].'px,高'.$img['h'].'px,大小'.intval((intval($img['size'])/1024)).'kb">
                <div class="img_he">'.$is_hege.'</div>
                <img src="'.$img["path"].'?x-oss-process=style/scale-cade2" width="'.$w.'" height="'.$h.'"  style="display: inline-block; vertical-align: middle; margin: 0 auto;">
                </a>
            </div>';
        }
        $html.= "<div class=\"clearfix\"></div>";
        $multipage.= "<div class=\"clearfix\"></div>";
        std_out(0,'',array("data_list"=>$html,'multipage'=>$multipage));
    }


    public function del_img_id(){
        $id=$this->input->get_post('id')?$this->input->get_post('id'):0;
        if(empty($id)){
            echo json_encode(array('status'=>-1,'msg'=>'删除失败'));
        }
        $this->ImgModel->update_data(array('status'=>-1),array('id'=>$id));
        $this->AdminOpenationModel->insertLog($id,7,'删除图片库图片');
        echo json_encode(array('status'=>1,'msg'=>'删除图片成功'));

    }
}